<template>
	<view class="payment">
		<view class="item">
			<text class="label">订单编号:</text>
			<text>{{ orderInfo.orderSn }}</text>
		</view>
		<view class="item">
			<text class="label">订单金额:</text>
			<text>{{ orderInfo.totalAmount }}元</text>
		</view>
		<view class="payType">
			<view class="title">选择支付方式</view>
			<view>
				<radio-group @change="radioChange">
					<label class="payType-item">
						<view>
							<image src="../../static/icons/alipay.png" mode=""></image>
							<text>支付宝支付</text>
						</view>
						<view><radio value="1" :checked="current == '1'" color="#354E44" /></view>
					</label>
					<label class="payType-item">
						<view>
							<image src="../../static/icons/wxpay.png" mode=""></image>
							<text>微信支付</text>
						</view>
						<view><radio value="2" :checked="current == '2'" color="#354E44" /></view>
					</label>
				</radio-group>
			</view>
		</view>
		<view class="btn" @tap="handlePay">立即支付</view>
		<view class="tips">
			<text>点击立即支付，即代表您同意</text>
			<text class="terms">《条款协议》</text>
		</view>
	</view>
</template>

<script>
import { getPreOrderById } from '../../api/order/confirmorder/index.js';
import { payConfirm } from '../../api/payment/index.js';
export default {
	data() {
		return {
			orderId: '', //  订单id
			orderInfo: {}, // 订单信息
			current: '1' // 支付方式,默认支付宝
		};
	},
	methods: {
		// 获取订单信息
		async getOrderInfo() {
			const res = await getPreOrderById(this.orderId);
			this.orderInfo = res.data.orderBase;
		},
		// 切换支付方式
		radioChange(e) {
			this.current = e.detail.value;
		},
		// 支付
		async handlePay() {
			const { success, message } = await payConfirm({
				orderId: this.orderId,
				payType: Number(this.current)
			});
			if (success) {
				uni.navigateTo({
					url: `payResult/payResult?price=${this.orderInfo.totalAmount}`
				});
			} else {
				uni.showToast({
					title: message,
					icon: 'error'
				});
			}
		}
	},
	onLoad(options) {
		this.orderId = options.id;
		this.getOrderInfo();
	}
};
</script>

<style lang="scss" scoped>
.payment {
	padding: 0 30rpx;
	.item {
		height: 90rpx;
		line-height: 90rpx;
		.label {
			font-size: 32rpx;
			color: #7d7d7d;
			margin-right: 10rpx;
		}
	}
	.payType {
		margin-top: 30rpx;
		.title {
			font-size: 34rpx;
		}
		.payType-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			line-height: 80rpx;
			height: 120rpx;
			image {
				width: 80rpx;
				height: 80rpx;
				margin-right: 20rpx;
				vertical-align: middle;
			}
			text {
				display: inline-block;
				height: 80rpx;
			}
		}
	}
	.btn {
		width: 70%;
		height: 80rpx;
		margin: 40rpx auto 10rpx;
		border-radius: 80rpx;
		color: #fff;
		background-color: #354e44;
		text-align: center;
		line-height: 80rpx;
		box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
	}
	.tips {
		font-size: 24rpx;
		color: #999;
		text-align: center;
		.terms {
			color: #5a9ef7;
		}
	}
}
</style>
